package com.financial.sys.service.bank.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.financial.model.pojo.TRecharge;
import com.financial.sys.mapper.bank.TRechargesMapper;
import com.financial.sys.query.UserRechargeQuery;
import com.financial.sys.service.bank.TRechargesService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class TRechargesServiceImpl extends ServiceImpl<TRechargesMapper, TRecharge> implements TRechargesService {

    @Override
    public Map<String, Object> selectUserRecharge(UserRechargeQuery userRechargeQuery) {
        Page<TRecharge> page=new Page<>(userRechargeQuery.getCurrentPage(),userRechargeQuery.getPageSize());
        Page<TRecharge>tRechargePage=page.setRecords(baseMapper.selectUserRecharge(userRechargeQuery,page));
        Map<String,Object>map=new HashMap<>();
        map.put("listData",tRechargePage.getRecords());
        map.put("totalPage",tRechargePage.getPages());
        map.put("totalCount",tRechargePage.getTotal());
        map.put("currentPage",userRechargeQuery.getCurrentPage());
        map.put("pageSize",userRechargeQuery.getPageSize());
        return map;
    }

    @Override
    public int UserRechargeAdd(TRecharge tRecharge) {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        tRecharge.setCreateTime(date);
        //暂时
        tRecharge.setTradeNo("112");
        tRecharge.setRechargeTime(date);
        return baseMapper.insert(tRecharge);
    }
}
